<?php
require_once('App-Top.php');
require_once('Authorizer.php');
require_once('GenFunctions.php');
require_once('DBConfigQuery.php');
require_once('../config.inc.php');
require_once('../Validation.php');

// Check if it is Member Mng
if (isset($_SESSION['SESS_USER_TYPE'])) {
    if (!isUserType_Members($_SESSION['SESS_USER_TYPE'])) {
        header("Location: AdminIndex.php");
        exit();
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Event Edit</title>
        <link href="StyleControl.css" rel="stylesheet" type="text/css" />
        <link type="text/css" href="../JQuery/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
        <script type="text/javascript" src="../JQuery/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="../JQuery/jquery-ui-1.7.2.custom.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $(".datepicker-inline").datepicker();
                $(".datefield").datepicker();
            });
        </script>
    </head>
    <body>

        <div id="sidebar">
            <h3>Reports</h3>
            <ul>
                <li><a href="#">Gate List</a></li>
                <li><a href="#">Members List</a></li>
            </ul>


            <?php
            require_once('MenuAdmin.php');
            ?>
        </div>

        <div id="mainbody">
            <h1>Event Edition</h1> <br />

            <form id="searchEvent" name="searchEvent" method="GET" action="AdminEventEdit.php" class="compactform">
                <fieldset class="clearfix">

                    <div class="threeper">
                        <label for="startdate"> Start Date
                        <input name="startdate" type="text" id="startdate" class="datefield" value="<?php if (isset($_GET['startdate'])) { echo $_GET['startdate']; } else { echo date("m/d/Y", mktime(0,0,0, date("m")-3, date("d"), date("Y")));} ?>"  /></label>

                        <label for="enddate"> End Date
                        <input name="enddate" type="text" id="enddate" class="datefield" value="<?php if (isset($_GET['enddate'])) { echo $_GET['enddate']; } else { echo date("m/d/Y", mktime(0,0,0, date("m")+3, date("d"), date("Y")));} ?>"  /></label>

                        <input type="submit" name="SearchEvent" value="Search Event" class="button"/>
                    </div>

                </fieldset>
            </form>


                
            <table summary="Edit Event Information" class="TSoft">

                <tr>
                    <td class="THeader"><a href="AdminEventEdit.php?qorder=etitle">Title</a></td>
                    <td class="THeader"><a href="AdminEventEdit.php?qorder=espkrname">Speaker</a></td>
                    <td class="THeader"><a href="AdminEventEdit.php?qorder=edate">Date</a></td>
                    <td class="THeader">Type</td>
                    <td class="THeader"><a href="AdminEventEdit.php?qorder=status">Status</a></td>
                    <td class="THeader">Edit</td>
                </tr>

            <?php

            $queryOrdering = "E.Date";
            if (isset($_GET['qorder'])) {
                switch(strtolower($_GET['qorder'])){
                    case 'etitle':
                        $queryOrdering = "E.Title";
                        break;

                    case 'status':
                        $queryOrdering = "E.Status";
                        break;

                    case 'espkrname':
                        $queryOrdering = "E.SpeakerName";
                        break;

                    default:
                        $queryOrdering = "E.Date";
                        break;
                }
            }

            $startDate = date("m/d/Y", mktime(0,0,0, date("m")-3, date("d"), date("Y")));
            if (isset($_GET['startdate'])) {
                $startDate = $_GET['startdate'];
            }

            $endDate = date("m/d/Y", mktime(0,0,0, date("m")+3, date("d"), date("Y")));
            if (isset($_GET['enddate'])) {
                $endDate = $_GET['enddate'];
            }

            $arrayStartDate = explode("/", $startDate); // [0]: Month, [1]: Day . [2]: Year
            $sqlDateStart = $arrayStartDate[2] . '-' . $arrayStartDate[0] . '-' . $arrayStartDate[1];

            $arrayEndDate = explode("/", $endDate); // [0]: Month, [1]: Day . [2]: Year
            $sqlDateEnd = $arrayEndDate[2] . '-' . $arrayEndDate[0] . '-' . $arrayEndDate[1];

            $q = sprintf($Q_TitleSpeakerDateTypeStatus_StartdateEnddateOrdering, $sqlDateStart, $sqlDateEnd, $queryOrdering);
            $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

            //Check whether the query was successful or not
            if ($r) {

                while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){

                    echo "<tr>";

                    $typeEvent = $row['Type'];
                    unset($row['Type']);
                    $statusEvent = $row['Status'];
                    unset($row['Status']);

                    $controllerDisplay = 0;
                    foreach ($row as $value) {
                        if ($controllerDisplay == 0)
                            $controllerDisplay = 1;
                        else
                            echo "<td class='TBody'>" . $value . "</td>";
                    }
                    $controllerDisplay = 0;
                    echo "<td class='TBody'>" . giveTypeEvent($typeEvent) . "</td>";
                    echo "<td class='TBody'>" . giveStatusEvent($statusEvent) . "</td>";
                    echo '<td class="TBody"><a href="AdminEventsEditEvent.php?eventid=' . $row['EventId'] . '">Edit</a></td>';
                    echo "</tr>";
                }
                mysqli_free_result($r);
                mysqli_close($dbc);
            } else {
                // Free DB
                mysqli_close($dbc);
                die("Query failed");
            }

            ?>


            </table>


        </div>

    </body>
</html>
<?php

    require_once('App-End.php');
?>

<!-- Designed: Jose Trujillo - 2011 -->